package com.fengxing.ams.web.facade;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.fengxing.ams.web.facade.intf.IVipFacade;
import com.fengxing.ams.web.facade.mouble.vip.IVipDAO;
import com.fengxing.ams.web.facade.mouble.vip.VipVO;

@Component
@Transactional
public class VipFacade implements IVipFacade {

	@Autowired
	IVipDAO vipDAO;
	
	@Override
	public VipVO queryVipInfo(String id) {
		return vipDAO.findOne(id);
	}
	
	public VipVO queryVipInfoByMobile(String phone) {
		return vipDAO.findByPhone(phone);
	}

	@Override
	public VipVO queryVipInfoByCarNumber(String id) {
		return vipDAO.findByCarNumber(id);
	}

	@Override
	public void purchase(String id, Integer time) {
		vipDAO.purchase(id, time);
	}

	@Override
	public void save(VipVO vipInfo) {
		vipDAO.save(vipInfo);
	}

	@Override
	public void updateTimeAndAmount(String id, Integer time, Integer amount) {
		vipDAO.updateTimeAndAmount(id, time, amount);
	}

	@Override
	public void updateVipInfo(VipVO vipInfo) {
		vipDAO.updateVipInfo(vipInfo.getId(), vipInfo.getName(), vipInfo.getPhone(), vipInfo.getCarNumber(), vipInfo.getCarType());
	}

	@Override
	public void renewForYearVip(VipVO vipInfo, Integer amount) {
		vipDAO.updateVipInfo(vipInfo.getId(), vipInfo.getYearExpiredDate(), amount);
	}

	@Override
	public List<VipVO> queryVipInfoAll() {
		Iterator<VipVO> iter = vipDAO.findAll().iterator();
		List<VipVO> vips = new ArrayList<VipVO> ();
		while (iter.hasNext()) {
			vips.add(iter.next());
		}
		System.out.println(vips.size());
		return vips;
	}

}
